package service;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

import androidx.annotation.Nullable;


public class MusicService2 extends Service{

   public MusicHelper musicHelper=null;

    private Log log;

    @Override
    public void onCreate(){
        log.d("MusicService------","onCreate");
        super.onCreate();
        musicHelper=new MusicHelper(this);
    }

    @Override
    public void onDestroy(){

        log.d("MusicService-------","onDestroy");
        super.onDestroy();
        musicHelper.destroy();
        musicHelper=null;

    }

    @Override
    public int onStartCommand(Intent intent,int flags,int starId){
        musicHelper.play();
        log.d("MusicService------","onStartCommand");
        return super.onStartCommand(intent,flags,starId);
    }



     public class MyBinder extends Binder {

        private MusicService2 service;


        public MyBinder(MusicService2 service){
            this.service=service;
        }

        public void play(){
            service.musicHelper.play();
        }

        public void next(){
            service.musicHelper.next();
        }

        public void pause(){
            service.musicHelper.pause();
        }

        public void destroy(){
            service.musicHelper.destroy();
        }

    }

    @Override
    public IBinder onBind(Intent intent){
        log.d("MusicService2------","onBind");
        return new MyBinder(this);
    }
}


